using OneDayModel.Interfaces;
using OneDayModel.Model;
using OneDayModel.PresentationLogic;

namespace OneDayModel.PresentationLogic
{
    public class CreateAlbumUILogic
    {
        private readonly ICreateAlbumUI createAlbumUI;
        private readonly AlbumsWorksModel albumWorksModel;

        public CreateAlbumUILogic(ICreateAlbumUI createAlbumUser, AlbumsWorksModel albumWorksModel)
        {
            createAlbumUI = createAlbumUser;
            this.albumWorksModel = albumWorksModel;

            createAlbumUser.onCreateAlbum += createAlbumUser_onCreateAlbum;
        }

        void createAlbumUser_onCreateAlbum(object sender, CreateAlbumArgs e)
        {
            if (string.IsNullOrEmpty(e.AlbumName))
            {
                createAlbumUI.ShowAlbumNameCantBeEmptyError();
                return;
            }

            IAlbum album = albumWorksModel.GetAlbumForLoggedInUser(e.AlbumName);
            if (album != null)
            {
                createAlbumUI.ShowAlbumAlreadyExistError(e.AlbumName);
                return;
            }

            album = albumWorksModel.CreateAlbum(e.AlbumName);
            createAlbumUI.ShownAlbum(album);
        }
    }
}